home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 API Bible / Windows 95 API Bible 3 Disc Set.iso / Win32 API Bible Book 1 of 3 / CHAPTE21 / EX7.C < prev    next >
C/C++ Source or Header  |  1995-05-29  |  2KB  |  48 lines

  1. #include <genstub.c>
  2.  
  3. LRESULT CALLBACK WndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
  4. {
  5.    static SYSTEMTIME stSystemTimeEntry;
  6.  
  7.    switch (uMsg)
  8.    {
  9.          case WM_CREATE:
  10.                GetSystemTime( &stSystemTimeEntry );
  11.                return( DefWindowProc(hWnd, uMsg, wParam, lParam ) );
  12.          case WM_COMMAND:
  13.                switch( LOWORD( wParam ) )
  14.                {
  15.                      case IDM_TEST:  // Add an hour to the clock.
  16.                      {
  17.                            SYSTEMTIME st;
  18.                            TCHAR      szBuffer[128];
  19.  
  20.                            GetLocalTime( &st );
  21.                            // Add one hour.
  22.                            st.wHour++;
  23.                            if (st.wHour==23)
  24.                               st.wHour = 0; // Wrap to next day.
  25.                            SetLocalTime( &st );
  26.                            // Display new local time.
  27.                            wsprintf(szBuffer, "The new time is %d:%d:%d.%d",
  28.                                     st.wHour, st.wMinute, st.wSecond,
  29.                                     st.wMilliseconds );
  30.                            MessageBox( hWnd, szBuffer, "Added One Hour",
  31.                                        MB_OK );
  32.                      }
  33.                      break;
  34.                      case IDM_EXIT:
  35.                            DestroyWindow( hWnd );
  36.                            break;
  37.                      break;
  38.                }
  39.                break;
  40.          case WM_DESTROY:
  41.                SetSystemTime( &stSystemTimeEntry );
  42.                PostQuitMessage( 0 );
  43.          break;
  44.          default:
  45.                return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
  46.    }
  47.    return( NULL );
  48. }